package com.cta.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.cta.dao.ProfilePersistence;
import com.cta.entity.PBXFactory;
import com.cta.entity.Profile;
import com.cta.entity.ServiceProvider;
import com.cta.entity.Trunk;
import com.cta.utils.SupportLoaderDelegate;

@Repository("profilePersistence")
public class ProfilePersistenceImpl extends BasePersistenceImpl implements
		ProfilePersistence {

	/**
	 * find all providers
	 * 
	 * @return
	 */
	public List<ServiceProvider> findAllProviders() {
		return getList("select p from ServiceProvider p");
	}

	/**
	 * find all trunk
	 * 
	 * @return
	 */
	public List<Trunk> findAllTrunks() {
		return getList("select t from Trunk t");
	}

	/**
	 * find list of trunk base on service provider id
	 * 
	 * @param serviceProviderId
	 * @return
	 */
	public List<Trunk> findTrunkByProvider(Long serviceProviderId) {
		return getList("select t from Trunk t where t.serviceProvider.id = ?1",
				serviceProviderId);
	}

	/**
	 * find all pbx factory
	 * 
	 * @return
	 */
	public List<PBXFactory> findAllPBXFactories() {
		return getList("select f from PBXFactory f");
	}

	/**
	 * find all profile of pbx
	 * 
	 * @return
	 */
	public List<Profile> findProfileByPBXId(Long pbxId) {
		return getList("select f from Profile f where f.pbx.id = ?1 order by f.sequence", pbxId);
	}
}
